<template>
    <div class="Project-List">
      <top-header></top-header>
      <div class="search-div" style="border-bottom: 1px solid #f3f6fa;">
        <div class="search-one-div">
          <search-one @search="onSearch"></search-one>
        </div>

        <span class="iconfont iconshaixuan"></span>
      </div>
      <div></div>
      <div class="common-list-body" v-fullheight>
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多内容" @load="onLoad">
          <router-link :to="{ name: 'projectDetail', query: {projectId: item.guid }}" class="list-item" v-for="(item, key) in listSource" :key="key">
            <img :src="item.showProjectMain"/>
            <div class="label">{{item.showProjectName}}</div>
          </router-link>
        </van-list>
      </van-pull-refresh>
    </div>
    </div>
</template>

<script lang="ts">
import { Component } from "vue-property-decorator";
import TopHeader from "@/components/TopHeader.vue";
import { List, Cell, PullRefresh } from "vant";
import SearchOne from "@/components/SearchOne.vue";
import Api from "@/api";
import Base from "@/utils/base";
import Enum from "@/typings/Enum";

@Component({
  name: "ProjectList",
  components: {
    TopHeader,
    SearchOne,
    VanList: List,
    VanCell: Cell,
    VanPullRefresh: PullRefresh
  }
})
export default class ProjectList extends Base{
  private listSource: any[] = [];
  private loading = false;
  private finished = false;
  private refreshing = false;

  private pageNum = 1;
  private pageSize = 20;
  private sortBy = "code"; // 排序字段
  private order = "desc"; // 排序顺序
  private showProjectName = "";
  private code = "";
  private searchValue = ""; // 消息内容


  onLoad(){
    if (this.finished) {
      return;
    }
    setTimeout(async () => {
      if (this.refreshing) {
        this.pageNum = 1;
        this.refreshing = false;
      }
      const res = await Api.GetProjectShowLibrary(this.listParams);
      if (res && res.code === 200) {
        if (this.pageNum === 1) {
          this.listSource = res.rows;
        } else {
          this.listSource.push(...res.rows);
        }
        if (res.total <= this.listSource.length) {
          this.finished = true;
        }
        this.pageNum++;
      } else {
        this.finished = true;
      }
      this.loading = false;
      }, 500);
  }

  onRefresh(){
    this.finished = false;
    this.loading = true;
    this.onLoad();
  }
  get listParams() {
    return {
      pageNum: this.pageNum,
      pageSize: this.pageSize,
      sortBy: this.sortBy,
      order: this.order,
      code: this.code,
      showProjectName: this.showProjectName,
      searchValue: this.searchValue
    };
  }

  onSearch(event: any) {
    this.showProjectName = event;
    this.refreshing = true;
    this.onRefresh();
  }
}
</script>

<style lang="less" scoped>
  .list-item{
    width: calc(100vw - 20px);
    background-color: #FFF;
    border-bottom: 1px solid #EEE;
    padding: 10px;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    img{
      width: 72px;
      height: 40px;
    }
    .label{
      width: 100%;
      font-size: 14px;
      padding: 0px 0 0px 10px;
      color: rgba(0,0,0,0.78);
      word-break: normal;
      white-space: pre-wrap;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }
</style>